﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class khcx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            return;
        }
        CreateDDItem();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strxm = this.xm.Value.Trim();
        string strlxfs = this.lxfs.Value.Trim();
        string strxb = this.xb.SelectedValue.Trim();
        string strnldy = this.nldy.Value.Trim();
        string strnlxy = this.nlxy.Value.Trim();
        string strquyu = this.quyu.SelectedValue.Trim();
        string strlaiyuan = this.lytj.SelectedValue.Trim();                
        string strlfrs = this.lfrs.Value.Trim();
        string strgzdw = this.gzdw.Value.Trim();
        string strxsdb = this.ywdb.SelectedValue;
        string stryxqd = this.yxqd.SelectedValue;
        string strfkfs = this.fkfs.SelectedValue;
        string strgxh = this.hx.SelectedValue;

        string strmianjidy = this.mjdy.Value.Trim();
        string strmianjixy = this.mjxy.Value.Trim();
        
        string strlc = this.lc.Value.Trim();
        string strlh = this.lh.SelectedValue;

        string strlfdy = lfss.Value.Trim();
        string strlfxy = lfjs.Value.Trim();

        string strlddy = ldss.Value.Trim();
        string strldxy = ldjs.Value.Trim();

        string strsql = "SELECT * FROM [fangwen] where '1'='1' ";
        if (strxm != "")
        {
            strsql += string.Format("and [name]='{0}' ",strxm);
        }

        if (strlxfs != "")
        {
            strsql += string.Format("and [phone]='{0}' ", strlxfs);
        }

        if (strxb != "")
        {
            strsql += string.Format("and [sex]='{0}' ", strxb);
        }


        if (strnldy != "")
        {
            strsql += string.Format("and [age]>='{0}' ", strnldy);
        }
        if (strnlxy != "")
        {
            strsql += string.Format("and [age]<='{0}' ", strnlxy);
        }

        if (strquyu != "" && strquyu != "0")
        {
            strsql += string.Format("and [quyu]='{0}' ", strquyu);
        }

        if (strlaiyuan != "" && strlaiyuan != "0")
        {
            strsql += string.Format("and [laiyuan]='{0}' ", strlaiyuan);
        }


        if (strgzdw != "")
        {
            strsql += string.Format("and [danwei] like '{0}' ", strgzdw);
        }
        if (strxsdb != "")
        {
            strsql += string.Format("and [p_id]='{0}' ", strxsdb);
        }


        if (stryxqd != "" && stryxqd != "0")
        {
            strsql += string.Format("and [yixiang]='{0}' ", stryxqd);
        }


        if (strfkfs != "" && strfkfs != "0")
        {
            strsql += string.Format("and [fukuan]='{0}' ", strfkfs);
        }
        if (strgxh != "" && strgxh != "0")
        {
            strsql += string.Format("and [huxing]='{0}' ", strgxh);
        }

        if (strmianjidy != "")
        {
            strsql += string.Format("and [mianji]>='{0}' ", strmianjidy);
        }

        if (strmianjixy != "")
        {
            strsql += string.Format("and [mianji]<='{0}' ", strmianjixy);
        }

        if (strlc != "" && strlc != "0")
        {
            strsql += string.Format("and [loucheng]='{0}' ", strlc);
        }

        if (strlh != "" && strlh != "0")
        {
            strsql += string.Format("and [louhao]='{0}' ", strlh);
        }

        if (strlfrs != "")
        {
            strsql += string.Format("and [laifangrenshu]='{0}' ", strlfrs);
        }


        if (this.lds.Checked)
        {
            if (strlddy != "")
            {
                strsql += string.Format("and [dt]>='{0}' ", strlddy);

            }
            if (strldxy != "")
            {
                strsql += string.Format("and [dt]<='{0}' ", strldxy);

            }

            strsql += string.Format("and [type]='{0}' ", "0");



        }
        if (this.lfs.Checked)
        {
            if (strlfdy != "")
            {
                strsql += string.Format("and [dt]>='{0}' ", strlfdy);

            }
            if (strlfxy != "")
            {
                strsql += string.Format("and [dt]<='{0}' ", strlfxy);

            }
            strsql += string.Format("and [type]='{0}' ", "1");

        }
        
        ManageData md = new ManageData(util.DATACONNECTION);
        if (md != null)
        {
            DataSet ds = md.ExecDS(strsql);
            Session["queryreslust"] = ds;
        }       

        Response.Redirect("khcxresult.aspx");                                          

    }

    protected void CreateDDItem()
    {
        util.CreateDownListWithQuanBu(this.lytj, "laiyuan");
        util.CreateDownListWithQuanBu(this.yxqd, "yixiang");
        util.CreateDownListWithQuanBu(this.fkfs, "fukuan");
        util.CreateDownListWithQuanBu(this.hx, "huxing");
        util.CreateDownListWithQuanBu(this.lh, "louhao");
        util.CreateDownListWithQuanBu(this.quyu, "quyu");
        util.CreateDownListSpVal(this.xb, "男", "1");
        util.CreateDownListSpVal(this.xb, "女", "0");
        util.CreateDownList(this.ywdb, "yuangong");
    }
}
